<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="600px"
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="auto" style="height:300px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="中文名称">
                <el-input v-model="form.nameCn" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="英文名称">
                <el-input v-model="form.nameEn" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="成长点">
                <el-input-number v-model.number="form.growthPoint" :min="0" :max="999999" controls-position="right" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="等级">
                <el-input-number v-model.number="form.level" :min="0" controls-position="right" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="默认等级">
                <el-radio
                  v-for="item in dict.true_false"
                  :key="item.id"
                  v-model="form.defaultStatus"
                  :label="item.dictKey"
                >{{ item.dictValue }}
                </el-radio>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="normal" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        style="width: 100%;"
        stripe
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55"       />
        <el-table-column prop="nameCn" label="名称"      >
          <template slot-scope="scope">
            <span>{{ scope.row.nameCn }}</span><br>
            <span>{{ scope.row.nameEn }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="level" label="等级"       />
        <el-table-column prop="growthPoint" label="成长点"      >
          <template slot-scope="scope">
            {{ dict.label.true_false[scope.row.growthPoint] }}
          </template>
        </el-table-column>
        <el-table-column prop="defaultStatus" label="是否默认"      >
          <template slot-scope="scope">
            {{ dict.label.true_false[scope.row.defaultStatus] }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkPer(['admin','memberLevel:edit','memberLevel:del'])"
          label="操作"
          width="150px"

        >
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMemberLevel from '@/api/ums/memberLevel'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  id: null,
  nameCn: null,
  nameEn: null,
  growthPoint: 0,
  level: 0,
  defaultStatus: false
}
export default {
  name: 'MemberLevel',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['true_false'],
  cruds() {
    return CRUD({ title: '会员等级', url: 'memberLevel/page', sort: 'id:desc', crudMethod: { ...crudMemberLevel }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'memberLevel:add'],
        edit: ['admin', 'memberLevel:edit'],
        del: ['admin', 'memberLevel:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'nameCn', display_name: '中文名称' },
        { key: 'nameEn', display_name: '英文名称' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
